package com.bamboo.eduservice.controller.front;

import com.bamboo.commonutils.ResponseEntity;
import com.bamboo.eduservice.entity.frontvo.CourseFrontVo;
import com.bamboo.eduservice.entity.frontvo.CourseWebVo;
import com.bamboo.eduservice.entity.vo.ChapterVo;
import com.bamboo.eduservice.feign.OrderFeignClient;
import com.bamboo.eduservice.service.EduChapterService;
import com.bamboo.eduservice.service.EduCourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 前台讲师控制器
 *
 * @author jack.wu
 * @version 1.0
 * @date 2020-07-18
 */
@Api(description = "前台课程管理")
@CrossOrigin
@RestController
@RequestMapping("/eduservice/front")
public class FrontCourseController {

    @Resource
    private EduCourseService courseService;

    @Resource
    private EduChapterService chapterService;

    @Resource
    private OrderFeignClient orderFeignClient;


    @ApiOperation(value = "前台分页查询课程")
    @PostMapping("courseList/{page}/{limit}")
    public ResponseEntity getFrontCourseList(@PathVariable long page, @PathVariable long limit,
                                             @RequestBody(required = false) CourseFrontVo courseFrontVo) {
        Map<String, Object> result = courseService.getFrontCourseList(page, limit, courseFrontVo);
        return ResponseEntity.ok().data(result);
    }


    @ApiOperation(value = "根据课程号查询章节和小节")
    @GetMapping("getChapterVideo/{courseId}")
    public ResponseEntity getChapterVideo(@PathVariable String courseId) {
        List<ChapterVo> chapterVideoList = chapterService.getChapterVideoByCourseId(courseId);
        return ResponseEntity.ok().data("chapterVideoList", chapterVideoList);
    }

    @ApiOperation(value = "根据课程号课程基础信息")
    @GetMapping("course/{id}")
    public ResponseEntity getCourseBaseInfo(@PathVariable String id) {
        CourseWebVo courseWebVo = courseService.getCourseBaseInfo(id);
        List<ChapterVo> chapterVideoList = chapterService.getChapterVideoByCourseId(id);
        // todo
//        orderFeignClient.isBuyCourse(id)
        return ResponseEntity.ok().data("courseWebVo", courseWebVo).data("chapterVideoList", chapterVideoList);
    }

    @ApiOperation(value = "根据课程号课程基础信息")
    @GetMapping("course/{id}")
    public CourseWebVo getCourseInfo(@PathVariable String id) {
        return courseService.getCourseBaseInfo(id);
    }

}
